﻿#include "PanelMeasureThread.h"

PanelMeasureThread::PanelMeasureThread(QObject *parent)
    :QThread(parent),
      m_stop(false),
      m_xSemaphore(0),
      m_ySemaphore(0),
      m_zSemaphore(0)
{

}

void PanelMeasureThread::setMainWindow(MainWindow *win)
{
    m_win = win;
}

void PanelMeasureThread::setStageControl(StageControl *stageControl)
{
    m_stageControl = stageControl;
}

void PanelMeasureThread::run()
{

}

void PanelMeasureThread::initSemaphore() // 确保每个 semaphore 都为 0
{
    int x = m_xSemaphore.available();
    int y = m_ySemaphore.available();
    int z = m_zSemaphore.available();
    if(x)
    {
        m_xSemaphore.acquire(x);
    }
    if(y)
    {
        m_ySemaphore.acquire(y);
    }
    if(z)
    {
        m_zSemaphore.acquire(z);
    }
}

bool PanelMeasureThread::waitGotoPos()
{
    if( !m_xSemaphore.tryAcquire(1, 5*1000) )
    {
        qWarning() << "xSemaphore timeout, Batch Measure failed!";
        return false;
    }
    if( !m_ySemaphore.tryAcquire(1, 5*1000) )
    {
        qWarning() << "ySemaphore timeout, Batch Measure failed!";
        return false;
    }
    if( !m_zSemaphore.tryAcquire(1, 5*1000) )
    {
        qWarning() << "zSemaphore timeout, Batch Measure failed!";
        return false;
    }
    return true;
}

void PanelMeasureThread::autoMeasure()
{

}
